home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Readers / Gui4Cli / Docs / Tutorials / IfTest.gc < prev    next >
Text File  |  1997-12-02  |  2KB  |  118 lines

  1. G4C
  2.  
  3. ; This is a convoluted function, to show you how if/elseif/while etc
  4. ; constructs work with the new additions. The gui loads up, goes
  5. ; through the stuf below, prints out the result, and quits.
  6.  
  7. ; it should print out :
  8. ; ** CORRECT 1 2 3 4 5 test finished
  9.  
  10.  
  11. xonload
  12.  
  13. if    1 = 5
  14. or    1 = 2
  15. or    1 = 9
  16.       say 'wrong.1\n'
  17. elseif 1 = 2
  18. or     2 = 3
  19.       say 'wrong.2\n'
  20. else
  21.       ifexists   dos ram
  22.       OrifExists dos dh0
  23.       and        1 = 0
  24.             say 'wrong.3\n'
  25.       elseif     1 != 0
  26.             a = 1
  27.             while $a < 5
  28.             and   1 = 1
  29.             gosub iftest.gc one    ; this is the correct one
  30.             endwhile
  31.       elseif    2 = 2
  32.       or        3 = 3
  33.             say 'wrong.4\n'          ; although this is also correct, the
  34.       else                           ; previous elseif has precedence
  35.             say 'wrong.5\n'
  36.       endif
  37.       if  2 = 2
  38.       and 3 = 4
  39.         say 'wrong.6\n'
  40.       endif
  41. endif
  42.  
  43. if   5 = 6
  44. or   6 = 7
  45. or   7 = 9
  46.       say 'wrong.end\n'
  47. elseifexists dos nodrive
  48. and          1 = 1
  49.       say 'wrong.end2\n'
  50. else
  51.       say 'test finished.\n'   ; this should also be printed.
  52. endif
  53.  
  54. guiquit iftest.gc
  55.  
  56.  
  57. ; --------------------- routine testing
  58.  
  59. xroutine one
  60. if   1 = 2
  61. or   2 = 3
  62.      say 'wrong r1.1\n'
  63. elseif 3 = 3
  64. and    4 = 4
  65.      if   5 = 5
  66.      and  6 = 6
  67.            gosub iftest.gc two    ; this is correct
  68.      elseif 7 = 9
  69.      or     9 = 9
  70.      or     1 = 1
  71.            say 'wrong r1.2\n'   ; also correct, but should NOT be executed
  72.      else
  73.        say 'wrong r1.3\n'
  74.      endif
  75. else
  76.      say 'wrong r1.4\n'
  77. endif
  78.  
  79.  
  80. xroutine two
  81. if     1 = 2
  82. or     2 = 3
  83.      say 'wrong r2.1\n'
  84. elseif 3 = 3
  85. and    4 = 4
  86.      if     5 = 5
  87.      or     7 = 6
  88.            if $a = 1
  89.               say '\n ** CORRECT! 1 '   ; Yes!
  90.           while $a < 5
  91.               or    1 = 2
  92.                     counter a inc 1
  93.             say '$a '
  94.               endwhile
  95.        endif
  96.      elseif 9 = 9
  97.      and    1 = 1
  98.            say 'wrong r2.2\n'
  99.      else
  100.        say 'wrong r2.3\n'
  101.      endif
  102. else
  103.      if   2 = 2
  104.      or   1 = 1
  105.         say 'wrong r2.4\n'
  106.      endif
  107. endif
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.